package com.eptok.gw.szcups.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author:heqishan, Email:heqishan@gmail.com 2013-3-15 下午04:32:00
 */
public class StringUtils {
	public static boolean checkNumAndWord(String s) {
		Pattern num_word_pattern = Pattern.compile("^[A-Za-z0-9]+$");
		return num_word_pattern.matcher(s).matches();
	}

	public static boolean checkNum(String s) {
		Pattern num_pattern = Pattern.compile("^[0-9]+$");
		return num_pattern.matcher(s).matches();
	}

	public static boolean checkNum(String s, int num) {
		Pattern num_pattern = Pattern.compile("^[0-9]{" + num + "}$");
		return num_pattern.matcher(s).matches();
	}

	public static boolean isEmpty(String value) {
		return (value == null) || (value.trim().length() == 0);
	}

	public static String replaceMiddBlank(String s) {
		return s.replaceAll("\\s", " ");
	}

	public static String replaceOther(String str) {
		Pattern p = Pattern.compile("[^A-Z0-9,.]");
		Matcher m = p.matcher(str);
		str = m.replaceAll("");
		return str;
	}

	public static String processStr(String str) {
		str = replaceMiddBlank(str);
		str = replaceOther(str);
		return str;
	}

	public static boolean validString(String s) {
		return s.matches(".*[^A-Z0-9,.].*");
	}
}
